home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 October / DPPCPRO1005.ISO / Download / Web Developer / webdeveloper.xpi / chrome / webdeveloper.jar / content / webdeveloper / common.js next >
Encoding:
JavaScript  |  2005-03-21  |  1.9 KB  |  80 lines

  1. // Formats a file size
  2. function webdeveloper_formatFileSize(fileSize)
  3. {
  4.     const stringBundle = document.getElementById("webdeveloper-string-bundle");
  5.  
  6.     // If the file size is set
  7.     if(fileSize)
  8.     {
  9.         // If the file size is greater than a kilobyte
  10.         if(fileSize > 1024)
  11.         {
  12.             return Math.round(fileSize / 1024) + " " + stringBundle.getString("webdeveloper_kilobytes");
  13.         }
  14.         else
  15.         {
  16.             return fileSize + " " + stringBundle.getString("webdeveloper_bytes");
  17.         }
  18.     }
  19.     else
  20.     {
  21.         return "";
  22.     }
  23. }
  24.  
  25. // Removes all child nodes from a node
  26. function webdeveloper_removeAllChildNodes(node)
  27. {
  28.     var childNodes = node.childNodes;
  29.  
  30.     // Loop through the child nodes
  31.     for(var i = 0; i < childNodes.length; i++)
  32.     {
  33.         node.removeChild(childNodes[i]);
  34.     }
  35.  
  36.     childNodes = node.childNodes;
  37.  
  38.     // Loop through the child nodes
  39.     while(childNodes.length > 0)
  40.     {
  41.         node.removeChild(childNodes[0]);
  42.     }
  43. }
  44.  
  45. // Removes a substring from a string
  46. function webdeveloper_removeSubstring(string, substring)
  47. {
  48.     // If the string was not empty
  49.     if(string)
  50.     {
  51.         const substringStart = string.indexOf(substring);
  52.  
  53.         // If the substring was found in the string
  54.         if(substring && substringStart != -1)
  55.         {
  56.             return string.substring(0, substringStart) + string.substring(substringStart + substring.length, string.length);
  57.         }
  58.         else
  59.         {
  60.             return string;
  61.         }
  62.     }
  63.     else
  64.     {
  65.         return "";
  66.     }
  67. }
  68.  
  69. // Tests if a string ends with the given string
  70. String.prototype.endsWith = function(endsWithString)
  71. {
  72.     return (this.substr(this.length - endsWithString.length) == endsWithString);
  73. }
  74.  
  75. // Trims leading and trailing spaces from a string
  76. String.prototype.trim = function()
  77. {
  78.     return this.replace(new RegExp("^\\s+|\\s+$", "gi"), "");
  79. }
  80.